
from access.core.codesnippetpattern import CodeSnippetPattern
import unittest

class CodeSnippetPatternTest(unittest.TestCase):
  def testConstruction (self):
    code_snippet_pattern = CodeSnippetPattern(ID_pattern = 'ID',
                                              value_pattern = 'value',
                                              test = ['a'])
    self.assertEqual(code_snippet_pattern.ID_pattern,
                     'ID',
                     'ID pattern field not set correctly.')
    self.assertEqual(code_snippet_pattern.value_pattern,
                     'value',
                     'Value pattern field not set correctly.')

  def testConstructionWithContext (self):
    code_snippet_pattern = CodeSnippetPattern(ID_pattern = 'ID',
                                              value_pattern = 'value',
                                              test = ['a'])
    self.assertEqual(code_snippet_pattern.ID_pattern,
                     'ID',
                     'ID pattern field not set correctly.')
    self.assertEqual(code_snippet_pattern.value_pattern,
                     'value',
                     'Value pattern field not set correctly.')
    self.assertIn('test',
                  code_snippet_pattern.context, 
                  'Pattern context is missing a key.')
    self.assertIn('a',
                  code_snippet_pattern.context['test'],
                  'Pattern context has incorrect data.')
